// ignore_for_file: must_be_immutable

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGWidget.dart';

class QGDisplaceListCell extends StatelessWidget {
  Map data;
  QGDisplaceListCell({super.key, required this.data});

  @override
  Widget build(BuildContext context) {
    var available = data["isLongtimeAvailable"] == "1";

    var start_time = data["start_time"] ?? "";
    if (start_time.length == 19) {
      start_time = start_time.substring(5, 5 + 11);
    }
    var end_time = data["end_time"] ?? "";
    if (end_time.length == 19) {
      end_time = end_time.substring(5, 5 + 11);
    }

    var start = DateTime.parse(data["start_time"]).millisecondsSinceEpoch;
    var end = DateTime.parse(data["end_time"]).millisecondsSinceEpoch;

    var curr = getCurrentTime();

    var state = "";
    var stateColor = const Color(0xffffffff);
    if (curr < start) {
      state = "未开始";
    } else if (curr >= start && curr < end) {
      state = "进行中";
      stateColor = const Color(0xFF28C445);
    } else {
      state = "已结束";
      stateColor = const Color.fromRGBO(255, 255, 255, 0.5);
    }

    bool ing = (curr >= start && curr < end);

    return 
    Stack(
       children: [
        Container(
          margin: EdgeInsets.all(15.rpx),
          child:  ClipRRect(
             borderRadius: BorderRadius.circular(8.rpx),
            child: AspectRatio(
              aspectRatio:16/9,
              child:QGImage(url:data["img_url"] ?? data["thumb_img"]),
            ),
          )
        )
       ,
          Positioned(
          right: 20.rpx,
          top: 20.rpx,
          child: QGImage(
            asset:state=='进行中'?'jinxingzhoing':state=='未开始'?'weikaishi':'jieshu',
             width: 70.rpx
          ),
        ),
        Positioned(
          left: 0,
          right: 0,
          bottom: 15.rpx,
          child:
          Container(
            padding: EdgeInsets.symmetric(vertical: 15.rpx),
            decoration: BoxDecoration(
              color: Color(0x80000000)
            ),
            child: Column(
            children: [
              Text(data["name"] ?? "",style: TextStyle(fontSize: 16,color: Color(0XFFFFFFFF),fontWeight: FontWeight.bold)),
              Text( 
                     available
                               ? "活动时间：长期有效"
                               : '活动时间：$start_time至$end_time',
                          style: TextStyle(
                              color: const Color.fromRGBO(255, 255, 255, 0.8),
                              fontSize: 11.rpx,
                              fontWeight: FontWeight.normal),
                        ),
            ],
          ),
          )
          ,
        ),
       ]
     );

    // Stack(
    //   children: [
    //     Container(
    //       padding: EdgeInsets.all(15.rpx),
    //       margin: EdgeInsets.only(top: 10.rpx, left: 10.rpx, right: 10.rpx),
    //       decoration: BoxDecoration(
    //         borderRadius: BorderRadius.circular(6.rpx),
    //         color: Color.fromRGBO(255, 255, 255, 0.3),
    //       ),
    //       child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
    //         ClipRRect(
    //             borderRadius: BorderRadius.circular(4.rpx),
    //             child: QGImage(
    //                 url: data["img_url"] ?? data["thumb_img"],
    //                 width: 80.rpx,
    //                 height: 80.rpx)),
    //         SizedBox(width: 15.rpx),
    //         Expanded(
    //           child: Column(
    //             mainAxisSize: MainAxisSize.max,
    //             crossAxisAlignment: CrossAxisAlignment.start,
    //             mainAxisAlignment: MainAxisAlignment.start,
    //             children: [
    //               Text(
    //                 data["name"] ?? "",
    //                 style: TextStyle(
    //                     color: Colors.white,
    //                     fontSize: 14.rpx,
    //                     fontWeight: FontWeight.bold),
    //               ),
    //               SizedBox(height: 20.rpx),
    //               Row(
    //                 children: [
    //                   QGImage(asset: "synthesis_time", width: 10.rpx),
    //                   SizedBox(width: 5.rpx),
    //                   Expanded(
    //                     child: Text(
    //                       available
    //                           ? "活动时间：长期有效"
    //                           : '活动时间：$start_time至$end_time',
    //                       style: TextStyle(
    //                           color: const Color.fromRGBO(255, 255, 255, 0.8),
    //                           fontSize: 11.rpx,
    //                           fontWeight: FontWeight.normal),
    //                     ),
    //                   ),
    //                 ],
    //               ),
    //             ],
    //           ),
    //         ),
    //       ]),
    //     ),
    //     Positioned(
    //       right: 10.rpx,
    //       top: 10.rpx,
    //       child: Container(
    //         padding: EdgeInsets.symmetric(horizontal: 20.rpx, vertical: 8.rpx),
    //         decoration: BoxDecoration(
    //           borderRadius: BorderRadius.only(
    //               topRight: Radius.circular(6.rpx),
    //               bottomLeft: Radius.circular(15.rpx)),
    //           color: Color.fromRGBO(0, 0, 0, 0.2),
    //         ),
    //         child: Text(
    //           state,
    //           style: TextStyle(
    //               color: stateColor,
    //               fontSize: 12.rpx,
    //               fontWeight: FontWeight.bold),
    //         ),
    //       ),
    //     )
    //   ],
    // );
  }
}
